<!DOCTYPE>
<html>
<head>
<script>
function myFunction(id)
{
var r=confirm("Bạn có chắc muốn xóa môn "+id+" không ? ");
if (r==true)
  {
  document.location = "control/staff-proc-del-course.php?courseid="+id;
  }
else
  {
  }

}
</script>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<link rel="stylesheet" href="styles/staff.css" type="text/css" />
<style>
table,td,th
td
{
text-align:center;
}
#coursename{
    width: 300px;
}
</style>
</head>
<body>



<?php
require("model/connect.php");

$baitren_mottrang = 5;

if ( !isset($_GET['page']) )
{
    $page = 0 ;
}else
{
    $page= $_GET['page'];
}
$sodu_lieu = mysql_num_rows(mysql_query("SELECT c.COURSE_ID,c.COURSE_NAME,c.COURSE_CREDIT,t.TRNP_ID,t.SECOND_COURSE_ID,t.COURSE_REL_TYPE FROM course c inner join courserelationship t ON c.COURSE_ID = t.COURSE_ID ") ) or die(mysql_error());

$sotrang = $sodu_lieu/$baitren_mottrang;

$result =mysql_query("SELECT c.COURSE_ID,c.COURSE_NAME,c.COURSE_CREDIT,t.TRNP_ID,t.SECOND_COURSE_ID,t.COURSE_REL_TYPE,t.COURSE_REL_ID FROM course c inner join courserelationship t ON c.COURSE_ID = t.COURSE_ID  ORDER BY t.COURSE_REL_ID DESC LIMIT ".$page*$baitren_mottrang.",".$baitren_mottrang) or die(mysql_error());
?>
<table class="gridtable">
<tr>
	<th>Mã môn học</th><th>Tên môn học</th><th>Số tín chỉ</th><th>Khoa quản lý</th><th>Môn ràng buộc</th><th>Loại ràng buộc</th><th>Tùy chọn</th>
</tr>
<tr>
<form action="control/staff-proc-add-course.php" method="POST">
<td><input type="text" name="courseid" required /></td><td><input type="text" name="coursename" id="coursename" width="50px" required/></td><td><input type="number" name="coursecredit" min="1" max="5" required/></td><td><input type="text" name="trnpid" required/></td><td><input type="text" name="coursesecond" required/></td><td><select name="reltype"><option value="1">Môn tiên quyết</option><option value="2">Môn học trước</option><option value="3">Môn song song</option><option value="4">Không có ràng buộc</option></select></td><td><input type="submit" value="Thêm"/></td>
</form>

</tr>
<?php
while ( $info = mysql_fetch_array($result )) 
{
    $reltype = "";
    if($info[5]==1){
        $reltype = "Môn tiên quyết";
    }if($info[5]==2){
        $reltype = "Môn học trước";
    }if($info[5]==3){
        $reltype = "Môn song song";
    }if($info[5]==4){
        $reltype = "Không có ràng buộc";
    }
    ?>
<tr>
<form action="control/staff-proc-edit-course.php" method="POST">
	<td><p><?php echo $info[0]?><p></td><td><input type="hidden" value="<?php echo "".$page?>" name="page"/><input type="hidden" name="courseid" value="<?php echo  $info[0]?>"/><input type="text" name="coursename" id="coursename" width="50px"  value="<?php echo  $info[1]?>"/></td><td><input type="number" name="coursecredit" min="1" max="5" value="<?php echo $info[2]?>"/></td><td><input type="text" name="trnpid" value="<?php echo "".$info[3]?>"/></td><td><input type="text" name="coursesecond" value="<?php echo "".$info[4]?>"/></td><td><select name="reltype"><option value="<?php echo $info[5]?>"><?php echo $reltype?></option><option value="1">Môn tiên quyết</option><option value="2">Môn học trước</option><option value="3">Môn song song</option><option value="4">Không có ràng buộc</option></select></td><td><input type="submit" value="Sửa"/></td>
<input type="hidden" value="<?echo $info[6]?>" name="relid"/>
</form>
<td><button onclick="myFunction('<?php echo "".$info[0]; ?>')">Xóa</button></td>
</tr>
    <?php
}
?>
</table>
<?php
for ( $page = 0; $page < $sotrang; $page ++ )
{
echo "<a href='staff-index.php?p=staff-man-course&page={$page}'>{$page} </a>";
} 

mysql_close();
?>
</body>
</html>

